package cn.iocoder.yudao.module.infra.util;

import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import org.slf4j.MDC;

/**
 * Description:
 * Author: li
 * Date: 2024/3/8
 */
public class TraceIdUtil {
    private static final String TRANSACTION_ID_KEY = "tid";

    public static void setTraceId(String tid) {
        MDC.put(TRANSACTION_ID_KEY, StrUtil.isNotEmpty(tid) ? tid : IdUtil.simpleUUID());
    }

    public static String getTraceId() {
        return MDC.get(TRANSACTION_ID_KEY);
    }

    public static void removeTraceId() {
        MDC.remove(TRANSACTION_ID_KEY);
    }

    public static void main(String[] args) {
        System.out.println(Integer.MAX_VALUE);
    }

}
